package net.freestu.sola.web.parser.Parse;

import java.net.MalformedURLException;
import java.net.URL;

import net.freestu.sola.web.util.MD5;

/**
 * 
 */
public class Page {

	
	private String id;
	
	private String school;

	private String site;

	private String urlhash;

	private String pagehash;

	private String url;

	private String redirect;

	private String title;

	private String update;
	
	private String delete;

	private String links;

	private String content;

	private String score;

	public Page(String id, String school,String url, String redirect, String title,
			String update, String links, String content, String score) {

		this.id = id;
		this.school=school;
		this.url = url;
		this.redirect = redirect;
		this.title = title;
		this.update = update;
		this.links = links;
		this.content = content;
		this.score = score;
		this.delete = "0";

		this.site = setSite();
		this.urlhash = setUrlHash();
		this.pagehash = setPageHash();
	}

	public Page(String id, String school,String site,String urlhash,String pagehash, String url, String redirect, String title,
			String update, String links, String content, String score){
		this.id = id;
		this.school=school;
		this.url = url;
		this.redirect = redirect;
		this.title = title;
		this.update = update;
		this.links = links;
		this.content = content;
		this.score = score;
		this.delete = "0";

		this.site = site;
		this.urlhash = urlhash;
		this.pagehash = pagehash;
		
	}
	
	private String setSite() {

		String str = null;
		try {
			URL u = new URL(url);
			str = u.getHost();
		} catch (MalformedURLException e) {
			str="d";
		}

		return str;
	}

	private String setUrlHash() {
		
		return MD5.MD5("url");
	}

	private String setPageHash() {
		
		String md5=MD5.MD5(content);
		return (md5+content.length());
	}
	
	public void markDelete()
	{
		this.delete = "1"; 
	}
	
	public String getDelete()
	{
		return delete;
	}

	public String getContent() {
		return content;
	}

	public String getId() {
		return id;
	}

	public String getLinks() {
		return links;
	}

	public String getPagehash() {
		return pagehash;
	}

	public String getRedirect() {
		return redirect;
	}

	public String getSchool() {
		return school;
	}

	public String getScore() {
		return score;
	}

	public String getSite() {
		return site;
	}

	public String getTitle() {
		return title;
	}

	public String getUpdate() {
		return update;
	}

	public String getUrl() {
		return url;
	}

	public String getUrlhash() {
		return urlhash;
	}
	
	
	public void printPage(){
		
		//System.out.println("`````````````````````````````````");
		System.out.println(id);
		System.out.println(school);
		System.out.println(url);
		System.out.println(redirect);
		System.out.println(title);
		System.out.println(update);
		System.out.println(links);
		System.out.println(content);
		System.out.println(score);

		System.out.println(site);
		System.out.println(urlhash);
		System.out.println(pagehash);
	}
	
	public static void main(String[] args){
		
		String id="1";
		String url="http://www.cdut.edu.cn/cdut";
		String school="成都理工大学";
		String redirect="http://www.cdut.edu.cn";
		String title="rrr";
		String update="2009.1.1";
		String links="http://www.sina.com\\http://www.baidu.com";
		String content="fffff";
		String score="100";
		Page p=new Page(id, school,url,redirect,title,update,links,content,score);
		System.out.println(p.getPagehash());
	}
}
